package dabs.engine.plant;

import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.Before;
import org.junit.Test;

import dabs.engine.DummyInterface;
import dabs.engine.GameEngine;
import dabs.engine.control.ComponentCommand;
import dabs.engine.environment.Environment;
import dabs.engine.environment.TemporaryDisable;
import dabs.ginterface.CommandParser;


public class ReactorTest {
	
	Reactor reactor;
	DummyInterface dinterface;
	ComponentCommand command;
	CommandParser parser;
	GameEngine geng;


	@Before
	public void setUp() throws Exception {
		dinterface = new DummyInterface();
		reactor = new Reactor(dinterface, "reactor", 50, 10, 10);
		parser = new CommandParser();
	}

	@Test
	public void testConversionRateChangeing() {
		reactor.setRodLevel(100);
		assertEquals(reactor.getConversionRate(),100);
		reactor.tick();
		reactor.tick();
		assertEquals(reactor.getConversionRate(),100);
	}

	
	
	@Test
	public void testCommandParsingIssues(){
		
		command = parser.asComponentCommand("reactor 40");
		reactor.runCommand(command);
		assertEquals(reactor.getConversionRate(),40);
		dinterface.makeEmpty();		
		command = (parser.asComponentCommand("reactor1 sth"));
		reactor.runCommand(command);
		assertTrue(dinterface.get().getDescription().contains("Rods must be set to"));		
		ArrayList<String> args = new ArrayList<String>();
		args.add("-10");
		reactor.runCommand(new ComponentCommand("reactor",  args));		
		assertTrue(reactor.getRodLevel() != -10);	//rod level can't be negative, an it is not set to that.
		assertTrue(reactor.getRodLevel() == 40);    //.. and stays as it was
	}
	
}
